//
//  IconButton.m
//  Jula_iOS
//
//  Created by Alimjan on 15/12/31.
//  Copyright © 2015年 Alimjan. All rights reserved.
//

#import "IconButton.h"

#include <stdio.h>
#include <wchar.h>
@implementation IconButton

-(NSString*)getStringFromWChar:(const wchar_t*) inStr

{
    NSString *str = [[NSString alloc] initWithBytes:inStr length:
                     4 encoding:NSUTF32LittleEndianStringEncoding];
    return str;
    
}
-(void)setIconSel:(NSString *)iconSel{
    wchar_t w = (wchar_t)strtoul([iconSel UTF8String],0,16);
    NSString *s = [self getStringFromWChar:&w];
    [self setTitle:s forState:UIControlStateSelected];
    UIFont *font = [UIFont fontWithName:@"jula" size:300];
    CGSize size = [s sizeWithAttributes:@{NSFontAttributeName:font}];
    CGFloat scale = size.width/self.frame.size.width;
    font = [UIFont fontWithName:@"jula" size:300.0/scale];
    self.titleLabel.font = font;
}
-(void)setIconNormal:(NSString *)iconNormal{
    wchar_t w = (wchar_t)strtoul([iconNormal UTF8String],0,16);
    NSString *s = [self getStringFromWChar:&w];
    [self setTitle:s forState:UIControlStateNormal];
    UIFont *font = [UIFont fontWithName:@"jula" size:300];
    CGSize size = [s sizeWithAttributes:@{NSFontAttributeName:font}];
    CGFloat scale = size.width/self.frame.size.width;
    font = [UIFont fontWithName:@"jula" size:300.0/scale];
    self.titleLabel.font = font;
}
-(void)setIconHighligted:(NSString *)iconHighligted{
    wchar_t w = (wchar_t)strtoul([iconHighligted UTF8String],0,16);
    NSString *s = [self getStringFromWChar:&w];
    [self setTitle:s forState:UIControlStateHighlighted];
    UIFont *font = [UIFont fontWithName:@"jula" size:300];
    CGSize size = [s sizeWithAttributes:@{NSFontAttributeName:font}];
    CGFloat scale = size.width/self.frame.size.width;
    font = [UIFont fontWithName:@"jula" size:300.0/scale];
    self.titleLabel.font = font;
}

@end
